﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace CCU.Update
{
    public partial class SelectPackage : Form
    {
        private Packages pks;

        public SelectPackage(Packages pks)
        {
            InitializeComponent();
            this.pks = pks;
            this.Fill();
        }

        private void Fill()
        {
            lbUpdate.Items.Clear();
            foreach (KeyValuePair<string, PackageInfo> objKVP in pks)
            {
                lbUpdate.Items.Add(objKVP.Value);
                lbUpdate.DisplayMember = "PackageName";
            }
        }

        private void btnNext_Click(object sender, EventArgs e)
        {
            PackageInfo pack = lbUpdate.SelectedItem as PackageInfo;
            if (pack != null)
            {
                if (MessageBox.Show("将安装更新包：[ " + pack.PackageName + " ], 确定？", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    this.SelectItemKey = pack.PackageID;
                    this.Hide();
                }
            }
        }

        public string SelectItemKey { get; set; }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
    }
}
